/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = __alignment.c                                      */
/*  NOTE      =                                                    */
/*  DATE      = 2016/04/11 by jikw                                 */
/*******************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include <corba/corba_comm.h>
#include <corba/corba_core.h>
#include <corba/ejb_comm.h>
#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "frbyte_buffer.h"
#include "frlist.h"
#include "frreport_comm.h"
#include "apmtest_cunit.h"
#include "apmtest_comm.h"

#include "../../../src/module/corba/config.h"

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

extern int __alignment(Frbyte_Packet *p_st_data, int i_pos, int i_alignment);

extern L7session_corba_private* __corba_private_create(void);

static void case1(void)
{
    Frbyte_Packet *p_st_data = NULL;
    int i_pos = 10;
    int i_alignment = 4;
    int i_ret = 0;

    i_ret = __alignment(p_st_data, i_pos, i_alignment);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    return;
}

static void case2(void)
{
    Frbyte_Packet *p_st_data = NULL;
    int i_pos = 10;
    int i_alignment = 4;
    int i_ret = 0;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *)"\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x30\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x30\x30", 24);

    bytebuff_skip(p_st_data, 15);

    i_ret = __alignment(p_st_data, i_pos, i_alignment);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(bytebuff_remaining(p_st_data), 6);

    bytebuff_free(&p_st_data);

    return;
}

static void case3(void)
{
    Frbyte_Packet *p_st_data = NULL;
    int i_pos = 10;
    int i_alignment = 4;
    int i_ret = 0;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *)"\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x30\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x30\x30", 24);

    bytebuff_skip(p_st_data, 23);

    i_ret = __alignment(p_st_data, i_pos, i_alignment);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    bytebuff_free(&p_st_data);

    return;
}

int add_suite__alignment(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __alignment()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", case1);
    CU_add_test(pSuite, "case2", case2);
    CU_add_test(pSuite, "case3", case3);

    return FR_SUCC;

}


